﻿using System.Security.Cryptography.X509Certificates;

namespace calendar
{
    internal class Program
    {
        
        static void Main(string[] args)
        {
            //设置边界大小
            int monthheight = 10;
            int monthwidth = 40;
            int x=0, y=0;
            //定义变量date 并设置初值；
            DateTime date = new DateTime(2022,1,1);
            //打印十二个月的日历模板
            for(int i = 1 ; i<13; i ++)
            {
                y = ((i - 1) / 3) * monthheight;
                x = ((i - 1) % 3) * monthwidth;
                string weekday = "日  一  二  三  四  五  六";
                Console.SetCursorPosition(x+8, y);
                Console.WriteLine((i)+"月");
                Console.SetCursorPosition(x, y+2);
                Console.Write(weekday);
            }
            do
            {
                //找到1号的位置
                if (date.Day == 1)
                {
                    x = (date.Month - 1) % 3 * monthwidth + (int)date.DayOfWeek * 4; 
                    y = (date.Month - 1) / 3 * monthheight+3;
                    Console.SetCursorPosition(x, y);
                    Console.Write("1");
                }
                else
                {
                    if (date.DayOfWeek == 0)
                    {
                        x = (date.Month - 1) % 3 * monthwidth;
                        y++;
                        Console.SetCursorPosition(x, y );
                        Console.Write(date.Day);
                    }
                    else
                    {
                        x += 4;
                        Console.SetCursorPosition(x, y);
                        Console.Write(date.Day);
                    }
                }
                date = date.AddDays(1);
            } while (date.Year==2022);

            
        }
    }
}